package com.wteam.dragon.model.controller;

import com.wteam.dragon.model.pojo.bean.Picture;
import com.wteam.dragon.model.pojo.vo.PictureVo;
import com.wteam.dragon.model.service.PictureService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.apps.security.annotation.AnonymousAccess;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * @Author 陈晓辉
 * @Date 2020/4/10 21:51
 */
@RestController
@Api(tags = "源：轮播图")
@RequestMapping("picture")
@RequiredArgsConstructor
public class PictureController {
    private final PictureService pictureService;

    @Log("添加图片")
    @ApiOperation("添加图片")
    @PostMapping("addPicture")
    @PreAuthorize("@el.check('addPicture')")
    public ResultMessage addPicture(PictureVo pictureVo){
        Picture picture = BeanUtil.from(pictureVo, Picture.class);
        return pictureService.addPicture(picture);
    }


    @Log("获得轮播图")
    @ApiOperation("获得轮播图")
    @GetMapping("listPicture")
    @AnonymousAccess
    public ResultMessage listPicture(Integer type){
        return pictureService.listPicture(type);
    }

    @Log("删除轮播图")
    @ApiOperation("删除轮播图")
    @DeleteMapping("delPicture")
    @PreAuthorize("@el.check('delPicture')")
    public ResultMessage delPicture(Long id){
        return pictureService.delPicture(id);
    }

}
